
package ija.xls.notation;

import ija.xls.notation.types.GameOperation;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 *
 * @author Radek Necas, xnecas18
 */
public class GameMove implements Iterable<DeskCoordinate> {
    
    protected List <DeskCoordinate> positions;
    protected GameOperation operation;
    
    public GameMove() {
        positions = new ArrayList<>();
        operation = null;
    }
    
    public GameMove(DeskCoordinate startPosition, GameOperation op, DeskCoordinate endPosition) {
        positions = new ArrayList<>();
        positions.add(startPosition);
        positions.add(endPosition);
        operation = op;
    }
    
    public void addPosition(DeskCoordinate p) {
        positions.add(p);
    }
    
    public void setOperation(GameOperation op) {
        operation = op;
    }
    
    public GameOperation getOperation() {
        return operation;
    }
    
    public int getPositionCount() {
        return positions.size();
    }
    
    public DeskCoordinate getFirstPosition() {
        return positions.get(0);
    }
    
    public DeskCoordinate getLastPosition() {
        return positions.get(positions.size() - 1);
    }
    
    public DeskCoordinate getPosition(int index) {
        if (index < 0 || index >= positions.size())
            return null;
        
        return positions.get(index);
    }

    @Override
    public Iterator<DeskCoordinate> iterator() {
        return positions.iterator();
    }
    

}
